//
//  SignalTableViewController.m
//  Select
//
//  Created by dihuijun on 17/3/15.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "SignalTableViewController.h"
#import "SignalTableChooseView.h"
@interface SignalTableViewController ()

/**   datasource   */
@property (nonatomic, strong) NSMutableArray *datasource;
/**   signalChooseView   */
@property (nonatomic, strong) SignalTableChooseView *signalChooseView;

@end

@implementation SignalTableViewController

/**   1.初始化datasource   */
- (NSMutableArray *)datasource{
    if(!_datasource){
        _datasource = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil];
    }
    return _datasource;
}

/**   signalChooseView   */
- (SignalTableChooseView *)signalChooseView{
    if(!_signalChooseView){
        _signalChooseView = [SignalTableChooseView shareTableViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.frame.size.height)];
        
        ///赋值
        _signalChooseView.datasource = self.datasource;
        
        //刷新表格
        [_signalChooseView reloadData];
        //选中的内容
        _signalChooseView.block = ^(NSString *content,NSIndexPath *indexPath){
            NSLog(@"content: %@ \n 第%zd行 \n",content,indexPath.row);
        };
        
    }
    return _signalChooseView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    ///1.setupNav
    [self setupNav];
    ///2.添加表格
    [self.view addSubview:self.signalChooseView];
    
}
/** 1.setupNav */
- (void)setupNav
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"tableView单选";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"AddDataSource" style:UIBarButtonItemStyleDone target:self action:@selector(ClickAddDataSource)];
}

/**
 *  点击添加数据 ClickAddDataSource
 */
- (void)ClickAddDataSource
{
    NSUInteger currentCount = self.datasource.count;
    for (int i=0; i<=6; i++) {
        [self.datasource addObject:[NSString stringWithFormat:@"%lu",currentCount+i]];
    }
    self.signalChooseView.datasource = self.datasource;
    [self.signalChooseView reloadData];
}

@end
